package it.low.game.client.gui.graphics;

import it.low.game.client.GameClient;
import it.low.game.client.gui.panel.GameBoardPanel;
import it.low.game.core.action.Action;
import it.low.game.core.element.activity.Targetable;
import it.low.game.core.location.MapPoint;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.util.HashMap;
import java.util.Map;

import javax.swing.ImageIcon;

public class GraphicPlaceholder {
	
	private boolean valid = false;
	private Map<Action.TYPE, ImageIcon> imageMap = null;
	
	private Targetable target = null;
	private Image image = null;
	private int halfHeight = 0;
	private int halfWidth = 0;
	
	public GraphicPlaceholder() {
		imageMap = new HashMap<Action.TYPE, ImageIcon>();
		ImageIcon imageIcon = new ImageIcon("images/flag/flag.png");
		imageMap.put(Action.TYPE.MOVE, imageIcon);		
	}
	
	public void update(Action.TYPE actionType, MapPoint mapPoint){
		this.target = mapPoint;
		ImageIcon imageIcon = imageMap.get(actionType);
		if(imageIcon!=null){
			image = imageIcon.getImage();
			halfHeight = imageIcon.getIconHeight();///2;
			halfWidth = imageIcon.getIconWidth()/2;
		}
		valid = true;
	}
	
	public boolean isValid(){
		return valid;
	}
	
	public void invalid(){
		valid = false;
	}
	
	public Targetable getTarget(){
		return this.target;
	}
	
	public void draw(Graphics g){
		if(valid){
			Point gamePanelPoint = GameClient.getGameSession().getGamePanelRelativePoint(target.getMapPosition());
			Point screenPoint = GameBoardPanel.getScreenRelativePoint(gamePanelPoint);
			g.drawImage(image,screenPoint.x-halfWidth,screenPoint.y-halfHeight,null);
		}
	}

}
